﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.Platform.DataContract;
using CommonsLib.DB;
using MaxLeaf.Platform.DALImplementation;
using MaxLeaf.Platform.Functions;
using CommonsLib.Utility;
using MaxLeaf.Platform.Commons;
using System.Data.Common;
using System.Data.SqlClient;

namespace MaxLeaf.Platform.BLLImplementation
{
    public class ImInvMasterBLL:BaseBLL
    {
         

        public override string FinterIDFields
        {
            get
            {
                return string.Format("{0},{1}", "FInterID", (int)FinterIDType.ImInvMaster);
            }
        }

        internal double GetRate(int intGoodsID, int intUnitID)
        {
            using (DBAccess dbcon = DataFunc.GetDBAccessByDataModelType(typeof(ImInvMasterDataModel)))
            {
                return new ImInvMasterDAL().GetRate(dbcon, intGoodsID, intUnitID);
            }
        }

        internal double GetWebPrice(int intGoodsID, int intUnitID, int intAreaID, int intUserID,int intPriceType)
        {
            using (DBAccess dbcon = DataFunc.GetDBAccessByDataModelType(typeof(ImInvMasterDataModel)))
            {
                return new ImInvMasterDAL().GetWebPrice(dbcon, intGoodsID, intUnitID, intAreaID, intUserID,  intPriceType);
            }
        }

        internal List<ImInvMasterDataModel> GetNoInvLocItems(int intCompanyID, int intGoodsID)
        {
            using (DBAccess dbcon = DataFunc.GetDBAccessByDataModelType(typeof(ImInvMasterDataModel)))
            {
                List<ImInvMasterDataModel> lst = new List<ImInvMasterDataModel>();

                using (DbDataReader rdr = ((ImInvMasterDAL)this.CurrentDAL).GetNoInvLocItems(dbcon, intCompanyID, intGoodsID)
                   )
                {
                    while (rdr.Read())
                    {
                        ImInvMasterDataModel model = new ImInvMasterDataModel();
                        DataFunc.Read(model, rdr, true);
                        lst.Add(model);
                    }
                }

                return lst;
                
            }
        }

        internal List<goods_categoryDataModel> GetGoodCateGoryBySCPCategory(int intCompanyID, int intSCPCategoryID)
        {
            using (DBAccess dbcon = DataFunc.GetDBAccessByDataModelType(typeof(ImInvMasterDataModel)))
            {
                List<goods_categoryDataModel> lst = new List<goods_categoryDataModel>();

                using (DbDataReader rdr = ((ImInvMasterDAL)this.CurrentDAL).GetGoodCateGoryBySCPCategory(dbcon, intCompanyID, intSCPCategoryID)
                   )
                {
                    while (rdr.Read())
                    {
                        goods_categoryDataModel model = new goods_categoryDataModel();
                        DataFunc.Read(model, rdr, true);
                        lst.Add(model);
                    }
                }

                return lst;

            }
        }

        internal double GetRateByItemID(int intItemID, int intUnitID)
        {
            using (DBAccess dbcon = DataFunc.GetDBAccessByDataModelType(typeof(ImInvMasterDataModel)))
            {
                int intGoodsID =CvtFunc.ToInt( dbcon.GetValue("select GoodsID  from ImInvMaster  where finterid=@itemid", new SqlParameter[] { new SqlParameter("@itemid", intItemID.ToString()) }));
                return new ImInvMasterDAL().GetRate(dbcon, intGoodsID, intUnitID);
            }
        }
    }
}
